package com.mycc.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mycc.common.Code;
import com.mycc.common.Result;
import com.mycc.damin.TbGuides;
import com.mycc.damin.TbTourists;
import com.mycc.service.GuidesService;
import com.mycc.service.TouristsService;
import com.mycc.service.ToursService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TouristsController {
    @Autowired
    private TouristsService touristsService;

    //添加
    @PostMapping("/addTourists")
    public Result addGuide(@RequestBody TbTourists tourists) {
        boolean flag = touristsService.addTourists(tourists);
        if (flag) {
            return new Result(Code.ADD_OK, "ok", flag);
        } else {
            return new Result(Code.ADD_FAIL, "error", flag);
        }
    }

    //删除
    @DeleteMapping("/deleteTourists/{id}")
    public Result deleteGuide(@PathVariable("id") int id) {
        boolean flag = touristsService.deleteTourists(id);
        if (flag) {
            return new Result(Code.DELETE_OK, "ok", flag);
        } else {
            return new Result(Code.DELETE_FAIL, "error", flag);
        }
    }

    //查询全部游客
    @GetMapping("/selAllTourists/{pageNumber}/{pageSize}")
    public IPage<TbTourists> selAll(@PathVariable Integer pageNumber, @PathVariable Integer pageSize) {
        return touristsService.selAllTourists(pageNumber, pageSize);
    }


    //通过id查询游客
    @GetMapping("/selByIdTourists/{id}")
    public Result selById(@PathVariable("id") int id) {
        TbTourists tourists = touristsService.selByCardTourists(id);
        if (tourists != null) {
            return new Result(Code.SELECT_OK, "ok", tourists);
        } else {
            return new Result(Code.SELECT_FAIL, "error", tourists);
        }
    }


    //通过名字查询游客
    @GetMapping("/selByNameTourists/{name}")
    public Result selByName(@PathVariable("name") String name) {
        List<TbTourists> list = touristsService.selByNameTourists(name);
        if (list != null) {
            return new Result(Code.SELECT_OK, "ok", list);
        } else {
            return new Result(Code.SELECT_FAIL, "error", list);
        }
    }

    //通过兴趣查询游客
    @GetMapping("/selByHobbyTourists/{location}")
    public Result selByLocation(@PathVariable("location") String location) {
        List<TbTourists> list = touristsService.selByLocationTourists(location);
        if (list != null) {
            return new Result(Code.SELECT_OK, "ok", list);
        } else {
            return new Result(Code.SELECT_FAIL, "error", list);
        }
    }

    //通过id修改游客信息
    @PutMapping("/updateTourists/{id}")
    public Result updateGuide(@PathVariable("id") int id, @RequestBody TbTourists tourists) {
        boolean flag = touristsService.updateTourists(id, tourists);
        if (flag) {
            return new Result(Code.SET_OK, "ok", flag);
        } else {
            return new Result(Code.SET_FAIL, "error", flag);
        }
    }

}
